package controller

import (
	"{{.ProjectName}}/internal/service"
	"{{.ProjectName}}/internal/validator"

	"gitee.com/wu-jin-feng/fgin"
	"github.com/gin-gonic/gin"
)

type GreeterController struct {
	F          *fgin.Fgin
	GreeterSvc *service.GreeterService
}

func NewGreeterController(f *fgin.Fgin, greeterSvc *service.GreeterService) *GreeterController {
	return &GreeterController{
		F:          f,
		GreeterSvc: greeterSvc,
	}
}

func (c *GreeterController) GetScheme(ctx *gin.Context) {
	input := validator.GetSchemeInput{}
	// validate 进行校验 且进行参数绑定
	if err := fgin.ValidateBindParams(ctx, &input); err != nil {
		fgin.ReturnJson(ctx, 400, nil, err)
		return
	}
	service := c.GreeterSvc
	out, err := service.GetScheme(ctx, input)
	if err != nil {
		fgin.ReturnJson(ctx, 400, nil, err)
		return
	}
	fgin.ReturnJson(ctx, 200, out, nil)
}
